home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS08.ADF / AmigaBasicProgs / YoYo < prev    next >
Text File  |  1986-04-02  |  3KB  |  71 lines

  1. 'Path: uwvax!seismo!lll-crg!ucdavis!ucbvax!vax135!cjp
  2. 'From: uwvax!vax135!cjp (Charles Poirier)
  3. 'Newsgroups: net.micro.amiga
  4. 'Subject: Yo-Yo source (Basic), possible Collisions BUG
  5. 'Date: 27 Jan 8604:51:31 GMT
  6. 'Organization: AT&T Bell Labs, Holmdel, NJ
  7.  
  8. 'I just got my Amiga (sans Development kit so far), running V1.1 of
  9. 'kickstart AND of AmigaBasic.  my first AmigaBasic program *almost*
  10. 'works, but there is something funny going ON with the detection of
  11. 'Collisions of a BOB (blitter object) with the WINDOW edge.  In the
  12. 'following program, the BOB bounces OFF edges normally, *except* when it
  13. 'hits the *same edge* twice In a row.  the second AND ALL subsequent
  14. 'times the BOB touches the same edge, no COLLISION is detected.  Having
  15. 'the BOB bounce OFF a different edge re-enables bounces ON the first
  16. 'edge but disables them ON the most recent edge.  Other anomalous
  17. 'behavior: when the BOB passes through a WINDOW edge due TO missing a
  18. 'COLLISION, it sometimes "bounces" OFF of the OFF-SCREEN continuation of
  19. 'a perpendicular "edge" (this I infer From where the BOB re-enters the
  20. 'SCREEN)0!  but sometimes it *doesn't* bounce, but passes through this
  21. 'second edge AS well.  this seems TO depend ON which edge is missing
  22. 'Collisions, *AND* ON which perpendicular edge.  I tried adding a
  23. '"collision on" In subr "bouncy", but it had no effect AT ALL (AS indeed
  24. 'is implied In the COLLISION documentation) so I removed it.
  25.  
  26. 'Please helpPRINT   is this a BUG In my program, In AmigaBasic, In the Amiga
  27. 'kernel, OR In the COLLISION detection hardwarePRINT   I hope it's just
  28. 'something I am neglecting TO RESET, but I can't figure out what from
  29. 'the AmigaBasic manual.  Note, the example program under OBJECT.SHAPE
  30. 'In the AmigaBasic manual doesn't use acceleration, so it would never
  31. 'find any BUG dealing with hitting the same side twice In a row.
  32.  
  33. entrypoint:
  34. 'yoyo: program to have an object yo-yo around the mouse pointer.
  35. ON COLLISION GOSUB bouncy
  36. COLLISION ON
  37. OPEN "i", #1, "Ball"  'output of my objedit run
  38. OBJECT.SHAPE 1, INPUT$(LOF(1),1)        'defines the object
  39. CLOSE 1
  40. foo% = MOUSE(0)     'sample the mouse position, then give it to object 1
  41. OBJECT.X 1, MOUSE(1): OBJECT.Y 1, MOUSE(2)
  42. OBJECT.VX 1, 40
  43. ax.kludge! = .033: ay.kludge! = .05
  44. OBJECT.ON
  45. OBJECT.START
  46.  
  47. WHILE (MOUSE(0) <> 1)     'sample mouse position, exit on click left
  48.    xdiff& = MOUSE(1) - OBJECT.X(1): ydiff& = MOUSE(2) - OBJECT.Y(1)
  49.    xsgn% = SGN(xdiff&): ysgn% = SGN(ydiff&)
  50.    xreal! = CSNG(xdiff&): yreal! = CSNG(ydiff&)
  51.    xreal! = ABS(xreal! * xreal! * xreal!)
  52.    yreal! = ABS(yreal! * yreal! * yreal!)
  53.    'adjust acceleration towards current mouse position as 3/2 power of dist
  54.    OBJECT.AX 1, (ax.kludge! * SQR(xreal!) * xsgn%)
  55.    OBJECT.AY 1, (ay.kludge! * SQR(yreal!) * ysgn%)
  56. WEND
  57. OBJECT.CLOSE
  58. END
  59.  
  60. bouncy:                       'collision interrupt subroutine
  61. wall% = COLLISION(1)
  62. IF (wall% = -1) OR (wall% = -3) THEN
  63.    OBJECT.VY 1, (-OBJECT.VY(1) * .5)  'bounce; reverse and halve y-component
  64. ELSEIF (wall% = -2) OR (wall% = -4) THEN
  65.    OBJECT.VX 1, (-OBJECT.VX(1) * .5)
  66. END IF
  67. OBJECT.START
  68. RETURN
  69.  
  70.  
  71.